import modelExtend from 'dva-model-extend'
import { pathMatchRegexp } from 'utils'
import { query${api?cap_first} } from 'api'
import { pageModel } from 'utils/model'
import { message } from 'antd'

export default modelExtend(pageModel, {
	namespace: '${namespace}',

	state: {
		filterItems:{},
	},

	subscriptions: {
		setup({ dispatch, history }) {
			history.listen(location => {
				if (pathMatchRegexp('${url}', location.pathname)) {
					const payload = location.query || { page: 1, pageSize: 10 }
					dispatch({
						type: 'query',
						payload,
					})
				}
			})
		},
	},

	effects: {
		*query({ payload = {} }, { call, put }) {
			const data = yield call(query${api?cap_first}, payload)
			const {error,result}=data
			if (!error) {
				yield put({
					type: 'querySuccess',
					payload: {
						list: result.rows,
						pagination: {
							current: Number(payload.page) || 1,
							pageSize: Number(payload.pageSize) || 10,
							total: result.total,
						},
					},
				})
			}
		},
	},

	reducers: {

	},

})
